﻿using System.Collections.Specialized;
using System.Text;
using System.Threading;
using System.Web;
using Dexter.Logger.Contracts;

namespace Dexter.Logger.Log4Net {
	internal static class Utils {
		public static void AddWebContextInfo (this ILogger logger ) {
			//HttpContext ctx = HttpContext.Current;
			
			//if ( ctx != null ) {
			//    logger.ThreadProperties["Url"] = ctx.Request.Url;
			//    logger.ThreadProperties["UrlReferrer"] = ctx.Request.UrlReferrer;
			//    logger.ThreadProperties["UserAgent"] = ctx.Request.UserAgent;
			//    logger.ThreadProperties["UserHostName"] = ctx.Request.UserHostName;
			//    logger.ThreadProperties["ServerVariables"] = ServerVariables ( ctx.Request.ServerVariables );
			//    logger.ThreadProperties["Form"] = ServerVariables ( ctx.Request.Form );
			//    logger.ThreadProperties["RawURL"] = ctx.Request.RawUrl;
			//    logger.ThreadProperties["ServerName"] = ctx.Server.MachineName;
			//    logger.ThreadProperties["ThreadLanguage"] = Thread.CurrentThread.CurrentCulture.DisplayName;
			//}
		}

		static string ServerVariables ( NameValueCollection coll ) {
			var sb = new StringBuilder ( );

			foreach ( object o in coll ) {
				sb.AppendFormat ( "{0}\r\n" , o );
			}

			return sb.ToString ( );
		}
	}
}